package tw.edu.tku.im.maze;
import org.json.JSONException;
import org.json.JSONObject;


public class LoginRepParser extends PacketParser {
   public static LoginRepParser INSTANCE = new LoginRepParser();
   
   private LoginRepParser() { }
   
   @Override
   public LoginRep parse(JSONObject jsonObj) throws JSONException {
      JSONObject result = jsonObj.getJSONObject("result");
      int state = result.getInt("state");
      if(result.isNull("playerInfo")) {
         return new LoginRep(state);
      } 
      else {
         JSONObject playerInfo = result.getJSONObject("playerInfo");
         return new LoginRep(state, PlayerInfo.parse(playerInfo));
      }
   }

   @Override
   public String acceptName() {
      return "loginResponse";
   }

}
